﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HA.ModFlow.Domain.DomainLayer;

namespace HA.ModFlow.Controls
{
   public class PCEVT
    {
       public PCEVT(ModFlowData mfData)
        {
            this._mfData=mfData;
            this._evt =(Evapotranspiration)mfData.SourceSinks.Evts.EVT.Clone();

            this._timePoint = new double[this._evt.Periods.Count + 1];
            this._timePoint[0] = 0.0;
            for (int i = 1; i <= this._evt.Periods.Count; i++)
            {
                this._timePoint[i] = this._timePoint[i - 1] + mfData.StressPeriods.InnerList[i - 1].PERLEN;
            }

            this._isUsePre = new List<bool>();
            foreach (bool item in mfData.SourceSinks.Evts.IsUsePrecious)
            {
                this._isUsePre.Add(item);
            }
            ///Elevation
            for (int i = 0; i < Evt.Periods.Count; i++)
            {
                double[,] elevation = (double[,])Evt.Periods[i].Elevation.Clone();

                this._elevationData.Add(elevation);

            }

            //MaxETRate数据
            for (int i = 0; i < Evt.Periods.Count; i++)
            {
                double[,] rate = (double[,])Evt.Periods[i].MaxETRate.Clone();

                this._maxETRateData.Add(rate);
            }

            //Extinction Depth
            for (int i = 0; i < Evt.Periods.Count; i++)
            {
                double[,] depth = (double[,])Evt.Periods[i].ExtinctDepth.Clone();

                this._extinctDepthData.Add(depth);
            }

            ///蒸发层位数组
            for (int i = 0; i < Evt.Periods.Count; i++)
            {
                int[,] data = (int[,])Evt.Periods[i].EvtLayer.Clone();

                this._evtLayerData.Add(data);
            }

            //应力期Index
            for (int i = 1; i <= this.Evt.Periods.Count; i++)
            {
                this._periodIndex.Add(i);
            }
        }
       #region 字段及属性

        ModFlowData _mfData;

        Evapotranspiration _evt;

        public Evapotranspiration Evt
        {
            get { return _evt; }
            set { _evt = value; }
        }

        double[] _timePoint;

        public double[] TimePoint
        {
            get { return _timePoint; }

        }

        List<bool> _isUsePre;

        public List<bool> IsUsePre
        {
            get { return _isUsePre; }
            set { _isUsePre = value; }
        }

        List<double[,]> _elevationData = new List<double[,]>();

        public List<double[,]> ElevationData
        {
            get { return _elevationData; }
            set { _elevationData = value; }
        }

        List<double[,]> _maxETRateData = new List<double[,]>();

        public List<double[,]> MaxETRateData
        {
            get { return _maxETRateData; }
            set { _maxETRateData = value; }
        }

        List<double[,]> _extinctDepthData = new List<double[,]>();

        public List<double[,]> ExtinctDepthData
        {
            get { return _extinctDepthData; }
            set { _extinctDepthData = value; }
        }

        List<int[,]> _evtLayerData = new List<int[,]>();

        public List<int[,]> EvtLayerData
        {
            get { return _evtLayerData; }
            set { _evtLayerData = value; }
        }

        List<int> _periodIndex = new List<int>();

        public List<int> PeriodIndex
        {
            get { return _periodIndex; }
        }
        #endregion

        #region 公共函数
        /// <summary>
        /// 将数据保存回数据内存
        /// </summary>
        public void ConfirmToDataCenter()
        {

            for (int i = 0; i < this.Evt.Periods.Count; i++)
            {
                _mfData.SourceSinks.Evts.IsUsePrecious[i] = this.IsUsePre[i];
                this.Evt.Periods[i].Elevation = this.ElevationData[i];
                this.Evt.Periods[i].ExtinctDepth = this.ExtinctDepthData[i];
                this.Evt.Periods[i].MaxETRate = this.MaxETRateData[i];
                this.Evt.Periods[i].EvtLayer = this.EvtLayerData[i];
                   

            }

            this._mfData.SourceSinks.Evts.SetEVT(this._evt);
        }

        #endregion
    }
}
